//
//  PassWordViewController.m
//  WZEfengAndEtong
//
//  Created by 李旭 on 16/7/21.
//  Copyright © 2016年 wanzhao. All rights reserved.
//

#import "PassWordViewController.h"
#import "Masonry.h"
#import "CAccountMgr.h"
#import "CAccountModel.h"
#import "MBProgressHUD+WZ.h"
@interface PassWordViewController ()<UITextFieldDelegate>
@property (nonatomic,weak) UITextField *passWord;
@property (nonatomic,weak) UIButton *okButton;
@end

@implementation PassWordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIView *backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"loginBackground"]];
    backgroundImageView.frame = self.view.bounds;
    [self.view addSubview:backgroundImageView];
      UIImageView *passwordImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"passwordLogoImage"]];
    [self.view addSubview:passwordImageView];
    [passwordImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(100);
        make.height.width.mas_equalTo(40);
        make.centerX.mas_equalTo(self.view);
    }];
    UITextField *textField = [[UITextField alloc]init];
    textField.placeholder = @"请输入密码";
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.secureTextEntry = YES;
    textField.delegate = self;
    [self.view addSubview:textField];
    self.passWord = textField;
    [textField becomeFirstResponder];
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(passwordImageView).offset(50);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(30);
        make.centerX.mas_equalTo(self.view);
    }];
    UIButton *button = [[UIButton alloc]init];
    [button addTarget:self action:@selector(checkPassword) forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"确定" forState:UIControlStateNormal];
    [button setBackgroundColor:RGBCOLOR(44, 170, 253)];
    [self.view addSubview:button];
    self.okButton = button;
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(textField).offset(50);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(30);
        make.centerX.mas_equalTo(self.view);
    }];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.passWord resignFirstResponder];
    return YES;
}

-(void)checkPassword
{
    if (self.passWord.text.length < 6 ) {
        [MBProgressHUD showError:@"密码不能小于6位"];
        return;
    }
    CAccountModel *account = [[[CAccountMgr alloc]init] getRecentlyLoginAccount];
    if ([account.passWord isEqualToString:self.passWord.text]) {
        [self dismissViewControllerAnimated:YES completion:nil];
//        [self.presentingViewController dismissViewControllerAnimated:NO completion:nil];
    }
    else
    {
        [MBProgressHUD showError:@"密码错误! 请重新输入"];
    }
}
@end
